package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageBean page(StudentQueryParam stu) {
        PageHelper.startPage(stu.getPage(),stu.getPageSize());

        List<Student> students = studentMapper.page(stu);

        Page<Student> page = (Page<Student>) students;
        return new PageBean(page.getTotal(),page.getResult());
    }


    @Override
    public void add(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());

        studentMapper.add(student);
    }

    @Override
    public Student getInfo(Integer id) {
        Student student = studentMapper.getInfo(id);
        return student;
    }

    @Override
    public void modify(Student s) {
        s.setUpdateTime(LocalDateTime.now());
        studentMapper.modify(s);
    }



    @Override
    public void delete(List ids) {
        studentMapper.delete(ids);
    }


    @Override
    public void violate(Integer id, Integer score) {
        studentMapper.violate(id,score);
    }


}
